﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.Clients;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.CientsCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.CientsCommandHandler
{
    public class AddInvoicingInforHandler : IRequestHandler<AddInvoicingInforCommand, APIResult<object>>
    {
        private readonly IBaseRepository<InvoicingInformation> _InvoicingInformation;
        private readonly IMapper mapper;

        public AddInvoicingInforHandler(IBaseRepository<InvoicingInformation> invoicingInformation, IMapper mapper)
        {
            _InvoicingInformation = invoicingInformation;
            this.mapper = mapper;
        }

        public Task<APIResult<object>> Handle(AddInvoicingInforCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code=APIEnum.添加成功;
            result.Msg=APIEnum.添加成功.ToString();
            var entity=mapper.Map<InvoicingInformation>(request);
            _InvoicingInformation.Add(entity);
            result.data = entity;
            return Task.FromResult(result);
        }
    }
}
